package des;
//File for testing
import java.io.*;
import java.security.Key;
import javax.crypto.KeyGenerator;

public class crypt 
{
		private static KeyGenerator kg;
		private static Key k;
		private static String path1;
		private static String path2;
		private static String uname;
		private static String mode;
		public static void main(String[] args){
		try
		{
			while(true)
			{
				System.out.println("Enter the mode (e/d)");
				//Read data into a buffer
				BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
				mode = br.readLine();
				//Encrypt file
				Encryptfile sec1 = new Encryptfile();
				//Decrypt file
				Decryptfile sec2=new Decryptfile();
			 
				if(mode.equalsIgnoreCase("e"))
				{
					//Generate key for encryption and decryption
					kg = KeyGenerator.getInstance("DES");
					k = kg.generateKey();
					System.out.println("Enter the name of file");
					BufferedReader br2= new BufferedReader(new InputStreamReader(System.in));
					path1=br2.readLine();
					sec1.setFileName(path1);
					//Encrypt file
					sec1.encrypt(k);
					path2=sec1.getfilename();
				}
		
				else if(mode.equalsIgnoreCase("d"))
				{
					BufferedReader br3= new BufferedReader(new InputStreamReader(System.in));
					uname=br3.readLine();
					sec2.setfname(uname);
					sec2.setpath(path2);
					//Decrypt file
					sec2.Decrypt(k);
					String dpath=sec2.getdfilename();
				}
				else
				{
					System.out.println("invalid mode");
				}
			}
		}
		catch(Exception e)
		{
			System.out.println("main e:"+e);
		}
	}
	crypt()	
	{
		super();
	}
}
